package hls.plugin.qywx.service;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @program: wx_send
 * @description: 借助map统计字符串出现的次数
 * @author: liuyuhao
 * @create: 2022-05-31 15:34
 * //////////////////////////
 **/
public class Test {

    public static void main(String[] args) {

        System.out.println("请输入需要统计的字符串：");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        Map<String, Integer> count = new LinkedHashMap<String, Integer>();
        for (int i = 0; i < str.length(); i++) {
            String s = String.valueOf(str.charAt(i));
            if (count.containsKey(s)) {
                count.put(s, count.get(s) + 1);
            } else {
                count.put(s, 1);
            }
        }

        //遍历
        for (Map.Entry<String, Integer> m : count.entrySet()) {
            System.out.println(m.getKey() + "出现的次数：" + m.getValue());
        }


    }
}
